
$(function () {
    var userId = sessionStorage.getItem('userId');
    function fmoney(s, n)
    {
        n = n > 0 && n <= 20 ? n : 2;
        s = parseFloat((s + '').replace(/[^\d\.-]/g, '')).toFixed(n) + '';
        var l = s.split('.') [0].split('').reverse(),
            r = s.split('.') [1];
        var  t = '';
        for (var i = 0; i < l.length; i++)
        {
            t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? ',' : '');
        }
        return t.split('').reverse().join('');
    };
    var IP='39.107.58.193:8080';
    //三级（市，区县，街道）直辖市，除此之外的省都是四级（省，市，区县，街道）
    var municipality = ["北京市","天津市","上海市","重庆市","香港特别行政区","澳门特别行政区"];
    //最小级zoom，省级zoom
    var ZOOM_PROVINCE_LEVEL = 5.5;
    //市级zoom
    var ZOOM_CITY_LEVEL = 7;
    //区县级zoom
    var ZOOM_DISTRICT_LEVEL = 11;
    //街道级zoom
    var ZOOM_STREET_LEVEL = 13;
    //缩放最大级别 zoom
    var ZOOM_MAX_LEVEL = 17;
    //当前zoom级别
    var current_zoom = ZOOM_PROVINCE_LEVEL;
    //省市区县级别
    var LEVEL_PROVINCE = 1;
    var LEVEL_CITY = 2;
    var LEVEL_DISTRICT = 3;
    var LEVEL_STREET = 4;
    //清除覆盖物
    //清除覆盖物
    function removeOverlay(map) {
        console.log(3);
        map.clearOverlays();
    }

    //设置所有覆盖物为可清除
    function setAllOverLayClear(map){
        var allOverlay = map.getOverlays();
        for(var overlay of allOverlay){
            overlay.enableMassClear();
        }
    }

    // 百度地图API功能
    function  map_init(map, level, data, markerClickCallback, center, isClick) {
        //设置所有覆盖物均可清除
        removeOverlay(map);
        setAllOverLayClear(map);
        //点击时需要设置zoom级别与定位中心，并将current_zoom置为当前zoom
        if(level != LEVEL_PROVINCE && center){
            if(level == LEVEL_CITY && isClick){
                console.log(22)
                map.setZoom(ZOOM_CITY_LEVEL);
                current_zoom = ZOOM_CITY_LEVEL;
                map.panTo(center);
            }
            else if(level == LEVEL_DISTRICT && isClick){
                map.setZoom(ZOOM_DISTRICT_LEVEL);
                current_zoom = ZOOM_DISTRICT_LEVEL;
                map.panTo(center);
            }
            else if(level == LEVEL_STREET && isClick){
                map.setZoom(ZOOM_STREET_LEVEL);
                current_zoom = ZOOM_STREET_LEVEL;
                map.panTo(center);
            }
        }
        var pointArray = new Array();
        for (var i = 0; i < data.length; i++) {
            var d=data[i];
            if(d.location){
                var p0 = data[i].location.split(",")[0];
                var p1 = data[i].location.split(",")[1];
                pointArray[i] = new BMap.Point(p0, p1);
                var pt = new BMap.Point(p0,p1);
                //标记文本
                var windowInfoContent;
                //4级文本展示
                var labelContent;
                if(level == LEVEL_PROVINCE){
                    d.pointsNum=d.pointsNum?d.pointsNum:0;
                    windowInfoContent="<p>"+d.provinceName+"</p></br><p>"+d.pointsNum+"点位</p></br><p>"+fmoney(d.billAmount,2)+"</p>";

                }else if(level == LEVEL_CITY){
                    d.pointsNum=d.pointsNum?d.pointsNum:0;
                    windowInfoContent="<p>"+d.provinceName+"</p></br><p>"+d.pointsNum+"点位</p></br><p>"+fmoney(d.billAmount,2)+"</p>";


                }else if(level == LEVEL_DISTRICT){
                    d.pointsNum=d.pointsNum?d.pointsNum:0;
                    windowInfoContent="<p>"+d.provinceName+"</p></br><p>"+d.pointsNum+"点位</p></br><p>"+fmoney(d.billAmount,2)+"</p>";


                }else if(level == LEVEL_STREET){
                    // windowInfoContent="<p>"+d.shopNamename+d.shopSale+"</p>";
                    labelContent =d.provinceName+'¥'+d.billAmount;
                }
                var maeker;
                var label;
                //1,2,3级地图选用自定义marker，4级地图选用默认地图，且label也不一样
                if(level != LEVEL_STREET){
                    //创建自定义icon以及自定义icon大小
                    var myIcon = new BMap.Icon("img/blue.png",new BMap.Size(65, 65));
                    marker = new BMap.Marker(pt,{icon:myIcon});
                    var opts = {
                        position:pt, // 指定文本标注所在的地理位置
                        offset:new BMap.Size(-20, -20)
                    };
                    label = new BMap.Label(windowInfoContent,opts);
                    label.setStyle({
                        color: "white",
                        fontSize: "12px",
                        height: "auto",
                        lineHeight: "8px",
                        fontFamily: "微软雅黑",
                        backgroundColor: 'none',
                        maxWidth: 'none',
                        border: 'none',
                        'font-weight':'bold'
                    });
                }else{
                    marker = new BMap.Marker(pt);
                    var opts = {
                        position: pt,// 指定文本标注所在的地理位置
                        offset:new BMap.Size(10, -30)
                    };
                    label = new BMap.Label(labelContent,opts);
                    label.setStyle({
                        color: "black",
                        fontSize: "12px",
                        height: "auto",
                        lineHeight: "15px",
                        fontFamily: "微软雅黑",
                        backgroundColor: 'white',
                        maxWidth: 'none'
                    });
                }
                bindMarkersEvent(map, marker, level, p0, p1);
                map.addOverlay(marker);    //增加点
                map.addOverlay(label);
            }
        }
        //让所有点在视野范围内
        // map.setViewport(pointArray);
    }



    //覆盖物点
    function bindMarkersEvent(map, marker, level, lng, lat){
        marker.addEventListener('click',function(){
            var center=new BMap.Point(lng,lat);
            console.log(center);
            if(level == LEVEL_PROVINCE){
                renderLevelTwoMap(map,center,true);
            }else if(level == LEVEL_CITY){
                renderLevelThreeMap(map,center,true);
            }
            else if(level == LEVEL_DISTRICT){
                renderLevelFourMap(map,center,true);
            }
        })

    }
    /**
     * 获得所有省份信息并渲染省级级（一级）地图
     * @param map map地图对象
     */
    function renderLevelOneMap(map) {
        var modelSend = {
            "model": 'province_board',
            "dillName": '',
            "dillType": '',
            "condition": {"year_month": ''},
            "item": {
                "sale_amount": [1, 2],
                "main_index": {"sale_amount": 1}//主指标
            }//数据指标
        };
        $.ajax({
            url:"http://"+IP+"/data-center/machinesBoard/getMachinesBoardInfo?token="+userId,
            type: "POST",
            data:{"paramData":JSON.stringify(modelSend)},
            success:function(data){
                console.log(data);
                var data=data.data;
                map_init(map , LEVEL_PROVINCE , data , bindMarkersEvent);
            }
        });
        // permissionService.getProvincesList(params).then((data) => {
        //     renderMarkersAndLabels(map , LEVEL_PROVINCE , data , bindMarkersEvent);
        //  });
    }

    //逆向解析省级坐标并渲染该省的市级（二级）地图
    function renderLevelTwoMap(map,center,isClick) {
        var center = center || map.getCenter();
        var isClick = isClick || false;
        var geoc = new BMap.Geocoder();
        geoc.getLocation(center, function (rs) {
            console.log(rs);
            //获得省份
            var province = rs.addressComponents.province;
            console.log(province);
            if(municipality.indexOf(province)== -1){
                var modelSend = {
                    "model": 'province_board',
                    "dillName": province,
                    "dillType": '1',
                    "condition": {"year_month": ''},
                    "item": {
                        "sale_amount": [1, 2],
                        "main_index": {"sale_amount": 1}//主指标
                    }//数据指标
                };
                console.log(modelSend);
                $.ajax({
                    url:"http://"+IP+"/data-center/machinesBoard/getMachinesBoardInfo?token="+userId,
                    type: "POST",
                    data:{"paramData":JSON.stringify(modelSend)},
                    success:function(data){
                        console.log(data);
                        var cityData=data.data;
                        map_init(map, LEVEL_CITY, cityData, bindMarkersEvent,center,isClick);
                    }
                });

            }else{
                var district = rs.addressComponents.city;
                console.log(district);
                //调用后台接口获取区县数据DistrictData
                var modelSend = {
                    "model": 'province_board',
                    "dillName": district,
                    "dillType": '2',
                    "condition": {"year_month": ''},
                    "item": {
                        "sale_amount": [1, 2],
                        "main_index": {"sale_amount": 1}//主指标
                    }//数据指标
                };
                $.ajax({
                    url:"http://"+IP+"/data-center/machinesBoard/getMachinesBoardInfo?token="+userId,
                    type: "POST",
                    data:{"paramData":JSON.stringify(modelSend)},
                    success:function(data){
                        console.log(data);
                        var district=data.data;
                        map_init(map, LEVEL_DISTRICT, district, bindMarkersEvent,center,isClick);
                    }
                });

            }
        })
    }

    function renderLevelThreeMap(map,center,isClick){
        center = center || map.getCenter();
        isClick = isClick || false;
        var geoc = new BMap.Geocoder();
        geoc.getLocation(center, function (rs) {
            console.log(rs);
            //获得市级
            var district = rs.addressComponents.city;
            console.log(district);
            var modelSend = {
                "model": 'province_board',
                "dillName": district,
                "dillType": '2',
                "condition": {"year_month": ''},
                "item": {
                    "sale_amount": [1, 2],
                    "main_index": {"sale_amount": 1}//主指标
                }//数据指标
            };
            $.ajax({
                url:"http://"+IP+"/data-center/machinesBoard/getMachinesBoardInfo?token="+userId,
                type: "POST",
                data:{"paramData":JSON.stringify(modelSend)},
                success:function(data){
                    console.log(data);
                    var district=data.data;
                    map_init(map, LEVEL_DISTRICT, district, bindMarkersEvent,center,isClick);
                }
            });
        });
    }

    function renderLevelFourMap(map,center,isClick){
        center = center || map.getCenter();
        isClick = isClick || false;
        var geoc = new BMap.Geocoder();
        geoc.getLocation(center, function (rs) {
            //获得区县
            var streetData = rs.addressComponents.district;
            console.log(streetData);
            //调用后台接口获取乡镇街道数据streetData
            var modelSend = {
                "model": 'province_board',
                "dillName": streetData,
                "dillType": '3',
                "condition": {"year_month": ''},
                "item": {
                    "sale_amount": [1, 2],
                    "main_index": {"sale_amount": 1}//主指标
                }//数据指标
            };
            $.ajax({
                url:"http://"+IP+"/data-center/machinesBoard/getMachinesBoardInfo?token="+userId,
                type: "POST",
                data:{"paramData":JSON.stringify(modelSend)},
                success:function(data){
                    console.log(data);
                    var streetData=data.data;
                    map_init(map, LEVEL_STREET, streetData, null,center,isClick);
                }
            });

        });
    }




    /**
     * zoom切换监听事件
     * @param map map地图对象
     */
    function bindZoomSwithListener(map) {
        var flag = true;
        var scrollFunc = function(e){
            if(flag){
                flag = false;
                setTimeout(function () {
                    //是否放大
                    var isUp = false;
                    //IE/Opera/Chrome 的滚轮判断为wheelDelta = +- 120 ，firefox的滚轮判断为detail = +- 3
                    //+120为放大，-120为缩小 -3为放大，+3为缩小
                    if(e.wheelDelta){
                        if(e.wheelDelta == 120){
                            isUp = true;
                            map.zoomIn();
                        }
                        else{
                            map.zoomOut();
                        }
                    }else if(e.detail){//Firefox
                        if(e.detail == -3){
                            isUp = true;
                            map.zoomIn();
                        }
                        else{
                            map.zoomOut();
                        }
                    }
                    //从一级跳二级
                    if(isUp && current_zoom == ZOOM_CITY_LEVEL - 1){
                        renderLevelTwoMap(map);
                    }
                    //从二级跳一级
                    else if(!isUp && current_zoom == ZOOM_CITY_LEVEL){
                        renderLevelOneMap(map);
                    }
                    //从二级跳三级
                    else if(isUp && current_zoom == ZOOM_DISTRICT_LEVEL - 1){
                        renderLevelThreeMap(map);
                    }
                    //从三级跳二级
                    else if(!isUp && current_zoom == ZOOM_DISTRICT_LEVEL){
                        renderLevelTwoMap(map);
                    }
                    //从三级跳四级
                    else if(isUp && current_zoom == ZOOM_STREET_LEVEL - 1){
                        renderLevelFourMap(map);
                    }
                    //从四级跳三级
                    else if(!isUp && current_zoom == ZOOM_STREET_LEVEL){
                        renderLevelThreeMap(map);
                    }
                    else{
                        map.removeOverlay();
                    }
                    if(isUp){
                        current_zoom = map.getZoom();
                    }else{
                        current_zoom = map.getZoom();
                    }
                    flag = true;
                },300);
            }
        };

    }
    var map = new BMap.Map("allmap");
    var point = new BMap.Point(116.404, 39.915);
    map.centerAndZoom(point,current_zoom);
    map.setMinZoom(ZOOM_PROVINCE_LEVEL);  //最小zoom缩放级别
    map.setMaxZoom(ZOOM_MAX_LEVEL); //最大zoom缩放级别
    map.addControl(new BMap.MapTypeControl());   //添加地图类型控件
    map.addControl(new BMap.NavigationControl({enableGeolocation: true}));
    map.addControl(new BMap.OverviewMapControl());
    map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
    bindZoomSwithListener(map); //初始化zoom缩放监听事件
    renderLevelOneMap(map);
    var vm=new Vue({
        el:"body",
        data:{
            //默认加载筛选条件存放容器
            "year_month":[],//年份
            "pay_modal":[],//支付方式
            "opera_modal":[],//运营模式
            "pro_source":[],//产品来源
            "spike":[],//通路
            "year":[],//年份
            "month":["01","02","03","04","05","06","07","08","09","10","11","12"],//月份
            "provCity":[],//省市
            "skuAll":[],//所有的sku信息
            "type":[],//所有的机台型号

            "provIdcity":[],//省对应的城市-//选中的省对应的城市列表列表信息
            "proName":"",//点击的省份名称
            "proId":"",//点击的省的id

            "getYear":'',//选中的年份
            "getMonth":'',//选中的月份
            "getPayItem":[],//选中的支付方式
            "getOperaItem":[],//选中的运营模式
            "getProSourceItem":[],//选中的产品来源

            "getTypeId":[],//选中的型号ID
            "getTypeLabel":[],//选中的型号label
            "getTypeStr":"",//选中的型号字符串

            "getModelId":[],//选中的机台ID
            "getModelLabel":[],//选中的机台label
            "getModelStr":"",//选中的机台字符串

            "getProviceId":[],//选中的省份ID
            "getProviceLabel":[],//选中的省份label
            "getProviceStr":"",//选中的身份字符串

            "getAllCities":[],//获取所有的城市信息
            "getCityId":[],//选中的城市ID
            "getCityLabel":[],//选中的城市label
            "getCityStr":"",//选中的城市字符串

            "getSpikeId":[],//选中的通路ID
            "getSpikeLabel":[],//选中的通路label
            "getSpikeStr":"",//选中的通路字符串

            "getSkuId":[],//选中的sku信息
            "getSkuStr":"",//选中的sku字符串
            "getSkuLabel":[],//选中的skulabel


            "getCityPoint":[],//选择的城市下对应的点位
            "getPointId":[],//选中的点位ID
            "getPointStr":[],//选中的点位字符串
            "getPointLabel":[],//选中的点位label

            "modelSelect":{
                "model":"province_board",
                "condition":{
                    "year_month":"",
                    "pay_modal":[],
                    "opera_modal":[],
                    "prod_source":[],
                    "passageway":[],
                    "provice":[],
                    "city":[],
                    "sku_msg":[],
                    "point_location":[]
                },//筛选条件
                "item": {"main_index":{"sale_amount":1},
                    "sale_amount":[1,2]}//主指标
            }//筛选条件的数据查询条件
        },
        methods:{
            //加载筛选条件
            setSelect:function(){
                this.$http.post('http://'+IP+'/data-center/month/getScreenTerm?token='+userId,
                    {},
                    {emulateJSON:true})
                    .then(
                        function(res){
                            console.log(res.data);
                            var data=res.data;
                            this.year=data.year_month;
                            this.pay_modal=data.pay_modal;
                            this.pro_source=data.prod_source;
                            this.opera_modal=data.opera_modal;
                            this.spike=data.spike;
                            this.provCity=data.provice;
                            this.getAllCities=getCityes(this.provCity);
                            this.skuAll=data.sku_msg;
                            this.type=data.type;
                            //console.log(this.getAllCities);
                        },
                        function(res){
                            console.log(res.data);
                        });

                //默认的请求
                var modelSend = {
                    "model": 'province_board',
                    "condition": {"year_month":''},
                    "item": {"sale_amount": [1],
                        "main_index": {"sale_amount": 1}//主指标
                    }//数据指标
                };
                console.log(modelSend)
                $.ajax({
                    url:"http://"+IP+"/data-center/machinesBoard/getMachinesBoardInfo?token="+userId,
                    type: "POST",
                    data:{"paramData":JSON.stringify(modelSend)},
                    success:function(data){
                        console.log(data);

                    }
                });
                //销售看板
                /*var yearSalesChart = new DRAWCROSSSTACK('http://192.168.1.130:8080/data-center/recentBorad/getRecentBoardInfo', modelSend, 'recentMach');
                yearSalesChart.draw();*/

            },
            //根据省份展示城市
            showCity:function(proId,proName){
                this.proName=proName;//动态变化选择市中省份名字
                this.proId=proId;
                //console.log(proId);
                //console.log(this.provCity);
                for(var i=0;i<this.provCity.length;i++)
                {
                    if(this.provCity[i].id==proId){
                        this.provIdcity=this.provCity[i].city;
                    }
                }
            },
            //获取选择的通路
            getSpike:function(){
                this.getSpikeLabel.length=0;
                for (var i = 0; i < this.getSpikeId.length; i++) {
                    var id = this.getSpikeId[i];
                    for (var j = 0; j < this.spike.length; j++) {
                        var thisSpike = this.spike[j];
                        if (thisSpike.id == id) {
                            this.getSpikeLabel.push(thisSpike.label);
                        }
                    }
                }
                //选择的通路长度为14，大于14省略之后的
                this.getSpikeStr=this.getSpikeLabel.join(",").length>15?this.getSpikeLabel.join(",").substr(0,15)+"...":this.getSpikeLabel.join(",");
            },
            //获取选择的sku
            getSku:function(){
                this.getSkuLabel.length=0;
                for (var i = 0; i < this.getSkuId.length; i++) {
                    var id = this.getSkuId[i];
                    for (var j = 0; j < this.skuAll.length; j++) {
                        var thisSpike = this.skuAll[j];
                        if (thisSpike.id == id) {
                            this.getSkuLabel.push(thisSpike.label);
                        }
                    }
                }
                //选择的通路长度为14，大于14省略之后的
                this.getSkuStr=this.getSkuLabel.join(",").length>15?this.getSkuLabel.join(",").substr(0,15)+"...":this.getSkuLabel.join(",");
            },
            //获取选择的机台
            getType:function(){
                this.getTypeLabel.length=0;
                for (var i = 0; i < this.getTypeId.length; i++) {
                    var id = this.getTypeId[i];
                    for (var j = 0; j < this.type.length; j++) {
                        var thisType = this.type[j];
                        if (thisType.id == id) {
                            this.getTypeLabel.push(thisType.label);
                        }
                    }
                }
                //选择的通路长度为14，大于14省略之后的
                this.getTypeStr=this.getTypeLabel.join(",").length>15?this.getTypeLabel.join(",").substr(0,15)+"...":this.getTypeLabel.join(",");
            },
            //获取选择的型号
            getModel:function(){
                this.getModelLabel.length=0;
                for (var i = 0; i < this.getModelId.length; i++) {
                    var id = this.getModelId[i];
                    for (var j = 0; j < this.model.length; j++) {
                        var thisModel = this.model[j];
                        if (thisModel.id == id) {
                            this.getModelLabel.push(thisModel.label);
                        }
                    }
                }
                //选择的通路长度为14，大于14省略之后的
                this.getModelStr=this.getModelLabel.join(",").length>15?this.getModelLabel.join(",").substr(0,15)+"...":this.getModelLabel.join(",");
            },
            //获取选择的省份
            getProv:function(){
                var arr=[];
                var selectPro=$("input[data-cacheval='false']");
                //console.log(selectPro);
                for(var i=0;i<selectPro.length;i++){
                    arr.push(selectPro[i].id);
                }
                this.getProviceId=arr;
                var arrLabel=[];
                for(var i=0;i<arr.length;i++){
                    for(var j=0;j<this.provCity.length;j++){
                        if(this.provCity[j].id==arr[i]){
                            arrLabel.push(this.provCity[j].label);
                        }
                    }
                }
                this.getProviceLabel=arrLabel;
                this.getProviceStr=this.getProviceLabel.join(",").length>15?this.getProviceLabel.join(",").substr(0,15)+"...":this.getProviceLabel.join(",");

            },
            //获取选择的城市
            getselCity:function(){
                //console.log(this.getAllCities);
                //根据选中的城市id获取选中的城市label
                var cityLabel=[];
                for(var i=0;i<this.getCityId.length;i++){
                    for(var j=0;j<this.getAllCities.length;j++){
                        if(this.getAllCities[j].id==this.getCityId[i]){
                            cityLabel.push(this.getAllCities[j].label);
                        }
                    }
                }
                this.getCityLabel=cityLabel;
            },
            //获取点位信息
            getPoint:function(){
                console.log(this.getCityId);
                var arr=this.getCityId;
                var sendData={"condition":{"city":arr}};
                console.log(sendData);
                this.$http.post('http://'+IP+'/data-center/month/getCityPoint?token='+userId,
                    {"paramData":JSON.stringify(sendData)},
                    {emulateJSON:true})
                    .then(
                        function(res){
                            console.log(res.data);
                            this.getCityPoint=res.data.city_point;
                        },
                        function(res){
                            console.log(res.data);
                        });
            },
            //获取选择的筛选条件并按条件绘图
            getSelect:function(){
                //console.log("年："+this.getYear);
                //console.log("月："+this.getMonth);
                //console.log("支付方式："+this.getPayItem);
                //console.log("运营模式："+this.getOperaItem);
                //console.log("产品来源："+this.getProSourceItem);
                //console.log("选中的通路："+this.getSpikeId);
                //console.log("选中的省份:"+this.getProviceId);
                //console.log("选中的城市:"+this.getCityId);

                //根据获取的筛选条件请求数据

                this.modelSelect.condition.year_month=this.getYear;
                this.modelSelect.condition.pay_modal=this.getPayItem;
                this.modelSelect.condition.opera_modal=this.getOperaItem;
                this.modelSelect.condition.prod_source=this.getProSourceItem;
                this.modelSelect.condition.passageway=this.getSpikeId;
                //选中的二级通路
                var getTwo=document.querySelectorAll('[name="accTwoCheck"]:checked');
                var arr=[];
                for(var i=0;i<getTwo.length;i++){
                    arr.push(getTwo[i].getAttribute('id'));
                }
                this.modelSelect.condition.getTwospike=arr;
                this.modelSelect.condition.provice=this.getProviceId;
                this.modelSelect.condition.city=this.getCityId;
                this.modelSelect.condition.sku_msg=this.getSkuId;
                this.modelSelect.condition.type=this.getTypeId;
                this.modelSelect.condition.point_location=this.getPointId;
                this.modelSelect.item={"main_index":{}};
                this.modelSelect.item.sale_amount=[1,2];
                this.modelSelect.item.main_index.sale_amount=1;
                var a=eval('('+JSON.stringify(this.modelSelect)+')');
                console.log(a);
                $.ajax({
                    url:"http://"+IP+"/data-center/machinesBoard/getMachinesBoardInfo?token="+userId,
                    type: "POST",
                    data:{"paramData":JSON.stringify(this.modelSelect)},
                    success:function(data){
                        console.log(data);
                        var cityData=data.data;
                        console.log(cityData);
                        var p0 = cityData[0].location.split(",")[0];
                        var p1 = cityData[0].location.split(",")[1];
                        var center = new BMap.Point(p0,p1);
                        var isClick = true;
                        renderLevelTwoMap(map,center,isClick);
                        // map_init(map , LEVEL_PROVINCE , cityData, bindMarkersEvent)
                    }
                });
                //销售看板
                // var yearSalesChart = new DRAWCROSSSTACK('http://192.168.1.130:8080/data-center/recentBorad/getRecentBoardInfo', a, 'recentMach');
                // yearSalesChart.draw();
                //第一个a的class为actice
                $("#selMain li:first-child a").removeClass().addClass('ui-link ui-btn ui-btn-active');
            },
            //根据选择的主指标进行画图
            getMain:function(e){
                var mainTag=e.target.getAttribute('tag');
                if(mainTag=="sale_amount"){
                    this.modelSelect.item={"main_index":{}};
                    this.modelSelect.item.sale_amount=[1,2];
                    this.modelSelect.item.main_index.sale_amount=1;
                }
                else if(mainTag=="sku_sum"){
                    this.modelSelect.item={"main_index":{}};
                    this.modelSelect.item.sku_sum=[1,2];
                    this.modelSelect.item.main_index.sku_sum=1;
                }
                else if(mainTag=="vender_sum"){
                    this.modelSelect.item={"main_index":{}};
                    this.modelSelect.item.vender_sum=[1,2];
                    this.modelSelect.item.main_index.vender_sum=1;
                }
                var a=eval('('+JSON.stringify(this.modelSelect)+')');
                console.log(a);
                //销售看板
                $.ajax({
                    url:"http://"+IP+"/data-center/machinesBoard/getMachinesBoardInfo?token="+userId,
                    type: "POST",
                    data:{"paramData":JSON.stringify(this.modelSelect)},
                    success:function(data){
                        console.log(data);

                    }
                });
                /*var yearSalesChart = new DRAWCROSSSTACK('http://192.168.1.130:8080/data-center/recentBorad/getRecentBoardInfo', a, 'recentMach');
                yearSalesChart.draw();*/
            },

        }
    });
    //默认执行页面
    vm.setSelect();
});
//获取所有的城市
function getCityes(arrList){
    var arr=[];
    for(var i=0;i<arrList.length;i++){
        var pro=arrList[i].city;
        //console.log(pro);
        for(var j=0;j<pro.length;j++){
            var city=pro[j];
            arr.push(city);
        }
    }
    return arr;
}